package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.flow.cmdb;


import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.cmdb.FlowFormPartStandardModify;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhengyr
 */
@Repository
public interface FlowFormPartStandardModifyRepo extends JpaRepository<FlowFormPartStandardModify, Long>, JpaSpecificationExecutor<FlowFormPartStandardModify> {
    /**
     * 根据流程Id检索表单
     */
    FlowFormPartStandardModify findByProcessId(String processId);

    List<FlowFormPartStandardModify> findAllByProcessId(String processId);

    @Query(value = "select distinct i.* from t_gw_flow_form_cpu_standard_new_detail d" +
            " left join t_gw_flow_form_part_standard_modify i on d.process_id = i.process_id  where i.is_close = 0 and i.modify_type = 0 and d.name = :name  ", nativeQuery = true)
    List<FlowFormPartStandardModify> findFlowCpuStandardName(String name);

    @Query(value = "select distinct i.* from t_gw_flow_form_cpu_standard_new_detail d" +
            " left join t_gw_flow_form_part_standard_modify i on d.process_id = i.process_id  where i.is_close = 0 and i.modify_type = 0 and d.part_num = :partNum  ", nativeQuery = true)
    List<FlowFormPartStandardModify> findFlowCpuPartNum(String partNum);

    @Query(value = "select distinct i.* from t_gw_flow_form_disk_standard_new_detail d" +
            " left join t_gw_flow_form_part_standard_modify i on d.process_id = i.process_id  where i.is_close = 0 and i.modify_type = 0 and d.name = :name  ", nativeQuery = true)
    List<FlowFormPartStandardModify> findFlowDiskStandardName(String name);

    @Query(value = "select distinct i.* from t_gw_flow_form_disk_standard_new_detail d" +
            " left join t_gw_flow_form_part_standard_modify i on d.process_id = i.process_id  where i.is_close = 0 and i.modify_type = 0 and d.part_num = :partNum  ", nativeQuery = true)
    List<FlowFormPartStandardModify> findFlowDiskPartNum(String partNum);

    @Query(value = "select distinct i.* from t_gw_flow_form_memory_standard_new_detail d" +
            " left join t_gw_flow_form_part_standard_modify i on d.process_id = i.process_id  where i.is_close = 0 and i.modify_type = 0 and d.name = :name  ", nativeQuery = true)
    List<FlowFormPartStandardModify> findFlowMemoryStandardName(String name);

    @Query(value = "select distinct i.* from t_gw_flow_form_memory_standard_new_detail d" +
            " left join t_gw_flow_form_part_standard_modify i on d.process_id = i.process_id  where i.is_close = 0 and i.modify_type = 0 and d.part_num = :partNum  ", nativeQuery = true)
    List<FlowFormPartStandardModify> findFlowMemoryPartNum(String partNum);

    @Query(value = "select distinct i.* from t_gw_flow_form_part_standard_new_detail d" +
            " left join t_gw_flow_form_part_standard_modify i on d.process_id = i.process_id  where i.is_close = 0 and i.modify_type = 0 and d.name = :name  ", nativeQuery = true)
    List<FlowFormPartStandardModify> findFlowPartStandardName(String name);

    @Query(value = "select distinct i.* from t_gw_flow_form_part_standard_new_detail d" +
            " left join t_gw_flow_form_part_standard_modify i on d.process_id = i.process_id  where i.is_close = 0 and i.modify_type = 0 and d.part_num = :partNum  ", nativeQuery = true)
    List<FlowFormPartStandardModify> findFlowPartPartNum(String partNum);
}
